﻿using UnityEngine;

namespace UFrame.AutoQuote
{
    
}

[CreateAssetMenu]
public class AutoQuoteAsset : ScriptableObject
{
    static AutoQuoteAsset data = null;

    public static AutoQuoteAsset I
    {
        get
        {
            if (data == null)
            {
                data = Resources.Load<AutoQuoteAsset>("AutoQuoteCode");

                if (data == null)
                {
                    Debug.LogError("请先创建 AutoQuoteCode ScriptableObject in Resources");
                }
            }
            
            

            return data;
        }
    }

    public AutoQuoteAsset()
    {
        
    }

    public string mSavePath = "";


    public string mFieldStart = "m";
    
    
    [SerializeField] public string result = "";
    //private static string mTransFuncAndEnd = "//Func\n{0}\n\t\t//FuncEnd";
    //private static string mTransFunc = "private void OnClick{0}()";
    // private static string mTransFuncBool = "private void OnClick{0}(bool b)";
    [SerializeField] public string fieldTemp = @"[SerializeField] private {0} {1} {2};";

    [SerializeField] public string mEventPrefix = "OnClick";
    //private static string mReStart = @"//Start[\s\S]*//End";
    //private static string mReFunc = @"//Func[\s\S]*//FuncEnd";

    [SerializeField] public string mFrontPrefix = "#";

    //[TextArea(3, 10)] public string mUsingNameSapce = "";

    [TextArea(2,3)] public string mUGUIButtonEvent = "{0}.{1}.AddListener(delegate {{ {2}({3}); }});";

    //生成代码相关的
    [TextArea(5,10)]  public string mUGUIAryEvent =
        @"for (int i = 0; i < {0}.{1}; i++)
        {{
            var b = {0}[i];
            {2}[i].{3}.AddListener(delegate {{ {4}(b); }});
        }}";


    //第二种方式生成函数
    [TextArea(8,10)] 
    public string mGTwoButtonEvent = @"
        delRegist = new EventDelegate(this, " + "\"{0}\"" + @");
        if({1} != null)
        {{
            delRegist.parameters[0].obj = {1}.gameObject.GetComponent<{2}>();
        }}
        {3}.{4}.Add(delRegist);";

    //private static string mGTwoInputEvent = @"
    //    delRegist = new EventDelegate(this, " + "\"{0}\"" + @");
    //    delRegist.parameters[0].obj = {1}.gameObject.GetComponent<UIInput>();
    //    {2}.onChange.Add(delRegist);";


    //private static string mGTwoToggleEvent = @"
    //    delRegist = new EventDelegate(this,  " + "\"{0}\"" + @");
    //    delRegist.parameters[0].obj = {1}.gameObject.GetComponent<UIToggle>();
    //    {2}.onChange.Add(delRegist);";

    [TextArea(8,10)]  public string mGTwoAryNGUIEvent =
        @"for (int i = 0; {0} != null && i < {0}.{1}; i++)
        {{
            delRegist = new EventDelegate(this," + "\"{2}\"" + @");
            delRegist.parameters[0].obj = {3}[i].gameObject.GetComponent<{4}>();
            {5}[i].{6}.Add(delRegist);
        }}";

  

    [TextArea(8, 30)] public string classTemp =
        @"
        using System.Collections;
        using System.Collections.Generic;
        using UnityEngine;
        using UnityEngine.UI;
        public partial class //@ClassName
        {
            //@Field

            partial void InitCustom();

            //@PartialMethod

            public void InitUI()
            {
                //@Init
                
                InitCustom();
            }
            
            //@Func

        }
        ";


    [TextArea(8, 30)] public string propertyTemp = @"public {0} {1}
    {
        get
        {
            return {5};
        }

        set
        {
            {6} = value;
        }
    }";
}